{% extends 'base.html' %}

{% block title %}{% if warehouse %}编辑仓库{% else %}新增仓库{% endif %} - 固定资产管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <h2>{% if warehouse %}编辑仓库{% else %}新增仓库{% endif %}</h2>
        
        <form method="post">
            {% csrf_token %}
            
            <div class="mb-3">
                <label for="name" class="form-label">仓库名称 *</label>
                <input type="text" class="form-control" id="name" name="name" value="{% if warehouse %}{{ warehouse.name }}{% else %}{{ name|default:'' }}{% endif %}" required>
            </div>
            
            <div class="mb-3">
                <label for="location" class="form-label">位置 *</label>
                <select class="form-select" id="location" name="location" required>
                    <option value="">请选择位置</option>
                    {% for location in locations %}
                        <option value="{{ location.id }}" {% if warehouse and warehouse.location_id == location.id or location_id|add:"0" == location.id %}selected{% endif %}>
                            {{ location.name }}
                        </option>
                    {% endfor %}
                </select>
            </div>
            
            <div class="mb-3">
                <label for="manager" class="form-label">管理员</label>
                <select class="form-select" id="manager" name="manager">
                    <option value="">请选择管理员</option>
                    {% for user in users %}
                        <option value="{{ user.id }}" {% if warehouse and warehouse.manager_id == user.id or manager_id|add:"0" == user.id %}selected{% endif %}>
                            {{ user.username }}
                        </option>
                    {% endfor %}
                </select>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">描述</label>
                <textarea class="form-control" id="description" name="description" rows="3">{% if warehouse %}{{ warehouse.description }}{% else %}{{ description|default:'' }}{% endif %}</textarea>
            </div>
            
            <div class="mb-3">
                <button type="submit" class="btn btn-primary">{% if warehouse %}更新{% else %}创建{% endif %}</button>
                <a href="{% url 'assets:warehouse_list' %}" class="btn btn-secondary">取消</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}